#!/usr/bin/perl
## Converts .avi .mkv -> .flv for streaming 
#576x432
use File::Basename;
use File::chdir;
chomp($path = @ARGV[0]);
chomp(@avifiles = `find $path -type f -name '*.avi'`);


for ($i=0; $i<@avifiles; $i++)
{
	
	$path = dirname(@avifiles[$i]);
	$CWD = $path;
	$old = basename(@avifiles[$i]);
	$new = $old;
	$new =~ s/.avi/.flv/;
	system(`ffmpeg  -i $old -ar 44100 -ab 96 -f flv -s 624x352 $new`);
#	system(`ffmpeg -threads 4 -y -i $old -ar 44100 -ab 96 -f mp4 -s 624x352 $new`);
#	system(`ffmpeg -threads 4 -i $old -vcodec libx264 -s 624x352 -flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -crf 24 -bt 256k -refs 1 -coder 0 -me_range 16 -subq 5 -partitions +parti4x4+parti8x8+partp8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec libfaac -ab 128k -ar 48000 -ac 2 $new`)
#	system(`ffmpeg -threads 4 -y -i $old -f mp4 -s 432x320 -aspect 432:320 -acodec aac -async 4800 -dts_delta_threshold 1 -vcodec xvid -qscale 7 $new`);
}

